package com.example.caimogu.fragmentImpl;

import android.util.Log;

import com.example.caimogu.Goods2Json.JsonUtil;
import com.example.caimogu.bean.Order;
import com.example.caimogu.http.HttpClientUtil;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Caimogu on 2016/4/21.
 */
public class UnhandledOrderImpl {


    public List<Order> getOrdersByIdImpl(String id){
        Log.i("caimogu","getOrdersByIdDao...");
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        HttpResponse httpResponse = httpClientUtil.getMyOrders(id);
        if(httpResponse == null){
            Log.i("caimogu","httpResponse is null");
        }
        HttpEntity httpEntity = httpResponse.getEntity();


        JSONObject jsonObject = null;
        try {
            //String  str = inputStream2String(httpEntity.getContent());
            //jsonObject = new JSONObject(new JSONTokener(inputStream2String(httpEntity.getContent())));
            String order = EntityUtils.toString(httpEntity);
            if(order != null)
                Log.i("caimogu", order);
            else
                Log.i("caimogu","毛都没得到？");
            JsonUtil jsonUtil = new JsonUtil();
            List<Order> listorder = jsonUtil.Json2ListOrder(order);

            return   listorder;

        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    public void changeOrdersStatus(final String oid, final int status){
        new Thread(new Runnable() {
            @Override
            public void run() {
                HttpClientUtil httpClientUtil = new HttpClientUtil();
                httpClientUtil.changeOrdersStatus(oid,status);

            }
        }).start();

    }

}
